#!/usr/bin/env python
# Copyright 2016 Google Inc. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

"""Creates adb.zip and fastboot.zip as standalone executables.

These files can be executed via:
  python adb.zip devices

The same way one would have run:
  python adb_debug.py devices

The zips can be transferred to other computers (and other CPU architectures) for
CPU and OS agnostic execution.
"""

import os
import sys
import zipfile


THIS_DIR = os.path.dirname(os.path.abspath(__file__))

def zipwritedir(z,src,dest,excludes=[]):
    z.write(src,dest)
    for i in os.listdir(src):
        if i not in excludes:
            z.write(os.path.join(src,i),os.path.join(dest,i))
def main():
    os.chdir(THIS_DIR)
    with zipfile.ZipFile('amtools.zip', 'w', zipfile.ZIP_DEFLATED) as z:
        zipwritedir(z,'../adb/adb','adb',excludes=[])
        z.write('../libusb1/libusb1.py','libusb1.py')
        z.write('../libusb1/usb1.py','usb1.py')
        zipwritedir(z,'../rsa/rsa','rsa',excludes=[])
    return 0


if __name__ == '__main__':
  sys.exit(main())
